<?php

/**
 * @Author:      zwh
 * @DateTime:    2016-7-27 11:04:08
 * @Description: 订单退货详情
 */
class ReturnOrderItem extends Eloquent
{
    protected $table = "return_order_item";
    
    /**
     * @Author:      zwh
     * @DateTime:    2016-7-29 14:46:28
     * @Description: 获取配件成本
     */
    public static function getCost($order_product_item_id,$product_type,$order_id){
        $moo=MaintenanceOutOrder::where('product_item_id',$order_product_item_id)->where('product_type',$product_type)->where('order_id',$order_id)->where('status',2)->select('id')->get()->toArray();
        $ids = array_column($moo,'id');
        $moi=MaintenanceOutItem::where('status',1)->whereIn('order_out_id',$ids)->get();
        $sum=0;
        foreach($moi as $_moi){
            $sum+=($_moi->number-$_moi->return_number)*$_moi->tax_purchase_price;
        }
        return $sum;
    }
    
    /**
     * @Author:      zwh
     * @DateTime:    2016-7-30 14:44:47
     * @Description: 执行退库
     */
    public static function implement($return_order_id,$roi,$order_id,$user,$ro,$approver,$approver_name,$return_type,$cancel_arr){
        return DB::transaction(function () use ($return_order_id,$roi,$order_id,$user,$ro,$approver,$approver_name,$return_type,$cancel_arr) {
            $lock_order = ReturnOrder::where("id",$return_order_id)->lockForUpdate()->first();
            $response = array('code' => 0, 'msg' => 'ok','result'=>array('return_order_id'=>$return_order_id));
            if(sizeof($roi)>0){
                foreach($roi as $_roi){
                    $moo_ids=MaintenanceOutOrder::where('order_id',$order_id)->where('status',2)->where('product_type',$_roi->product_type)->where('product_item_id',$_roi->order_product_item_id)->select('id')->get()->toArray();
                    $moo_ids = array_column($moo_ids, 'id');
                    $sum=MaintenanceOutOrder::where('order_id',$order_id)->where('status',2)->where('product_type',$_roi->product_type)->where('product_item_id',$_roi->order_product_item_id)->sum('number');
                    if($_roi->number<=0){
                        DB::rollback();
                        $response = Lang::get("scs_error.maintenance_return_number_error_70004");
                        return $response;
                    }
                    $mro=MaintenanceReturnOrder::whereIn('out_order_id',$moo_ids)->whereIn('status',array(0,1))->sum('number');
                    $total=$mro+$_roi->number;
                    if($_roi->product_type=='promotion'){
                        DB::rollback();
                        $response = Lang::get("scs_error.maintenance_return_error_70003");
                        return $response;
                    }
                    if($total>$sum){//如果 该批次的 退货总数大于出库总数
                        DB::rollback();
                        $response = Lang::get("scs_error.maintenance_return_error_70002");
                    }
                    $item=null;
                    switch ($_roi->product_type) {
                        case 'enterprise':
                            $item=OrderProductEsItem::find($_roi->order_product_item_id);
                            $type=$item->item_type;
                            break;
                        case 'activity':
                            $item=OrderProductAcItem::find($_roi->order_product_item_id);
                            $type=$item->item_type;
                            break;
                        case 'promotion':
                            $item=OrderProductItem::find($_roi->order_product_item_id);
                            $type=$item->item_type;
                            break;
                        case 'base':
                            $item=OrderProductBaseItem::find($_roi->order_product_item_id);
                            $type=$item->item_type;
                            break;
                        case 'non_standard':
                            $item=OrderProductNonStandard::find($_roi->order_product_item_id);
                            $type=$item->type;
                            break;
                        case 'service_card':
                            $item=OrderProductScItem::find($_roi->order_product_item_id);
                            $type=$item->item_type;
                            break;
                    }
                    //退货记录
                    $return_orders=array();
                    if(sizeof($moo_ids)>0){
                        $return_orders=ReturnOrderItem::returnItem($user,$type,$item->item_id,$_roi->product_type,$_roi->order_product_item_id,$order_id,$_roi->number,$moo_ids,$return_order_id,array());
                    }
                    
                    //根据退货记录进行入库操作
                    $time=date('Y-m-d H:i:s',time());
                    $msl=new MaintenanceStorageList;
                    $id=Common::createId();
                    $msl->id=$id;
                    $msl->shop_id=$user->shop_id;
                    $msl->date=date("Y-m-d",time());
                    $msl->supplier=0;
                    $msl->storage_type=2;//入库类型为 退货
                    $msl->pay_type=0;
                    $msl->status=1;
                    $msl->cust_id=$user->id;
                    $msl->type=3;
                    $msl->desc="订单退货";
                    $msl->create_by=$user->id;
                    $msl->implement_by=$user->id;
                    $msl->implement_time=$time;
                    $msl->save();
                    foreach ($return_orders as $_ro) {//循环处理 选定的 退库单
                        //查找该退库单的 相应地出库申请单
                        $moo=MaintenanceOutOrder::find($_ro->out_order_id);
                        if(is_null($moo)||$moo->status!=2){
                            DB::rollback();
                            $response = Lang::get("scs_error.maintenance_out_order_statuserror_60010");
                            $response["result"]=array('编号' .$_ro->id."退库单 对应出库记录不存在");
                            return $response;
                        }
                        //查询该 耗材的仓库信息
                        $mw=MaintenanceWarehouse::where("shop_id",$user->shop_id)->where("item_id",$_ro->item_id)->first();
                        //添加退货的时候进行数量判断  此处不进行 数量判断
                        //查找该出库申请单 对应的的 出库耗材批次
                        $moi=MaintenanceOutItem::getReturnStorageItem($moo,$_ro->number);// 返回的结果包含 该出库申请对应的出库记录 的可退数量和 出库记录对应的入库记录
                        foreach ($moi as $_moi) {
                            //查找出库记录 修改退货数量 记录
                            $_mo=MaintenanceOutItem::find($_moi->id);
                            $_mo->return_numer=$_mo->return_numer+$_moi->user_number;
                            $_mo->save();
                            //修改入库记录的使用个数  将退的货物 退回 原来的额入库耗材批次中
                            $msi=MaintenanceStorageItem::find($_moi->ms_id);
                            $msi->current_number=$msi->current_number+$_moi->user_number;
                            $msi->save();
                            //添加 该订单退货的 的入库耗材批次
                            $msi=new MaintenanceStorageItem;
                            $msi->list_id=$id;
                            $msi->tax_purchase_price=0;
                            $msi->no_tax_purchase_price=0;
                            $msi->production_date=0;
                            $msi->tax_plan_costs=0;
                            $msi->no_tax_plan_costs=0;
                            $msi->number=$_moi->user_number;
                            $msi->tax_purchase_subtotal=0;
                            $msi->current_number=0;
                            $msi->location="";
                            $msi->production_date=date("Y-m-d",time());//次数 date 无用
                            $msi->own_id=$user->id;
                            $msi->data_id=$_mo->data_id;
                            $msi->item_type=$_ro->type;
                            $msi->item_id=$_ro->item_id;
                            $msi->pack_unit=0;
                            $msi->shop_id=$user->shop_id;
                            $msi->type=2;//2 是退库
                            $msi->status=1;
                            $msi->created_by=$user->id;
                            // if($_ro->type==0){//说明是 标准耗材
                                $si=SupplyItem::find($_ro->item_id);
                                $msi->code=$si->code;
                                // $msi->name=$si->brand->brand_name." ".$si->series->name." ".$si->model;
                                $msi->name=$si->name;
                                $msi->subject=$si->supply_classification_id;
                                $msi->model=$si->model;
                            // }else{
                            //     $sins=SupplyItemNonStandard::find($_ro->item_id);
                            //     $msi->code=$sins->code;
                            //     $msi->name=$sins->name;
                            //     $msi->subject=$sins->subject;
                            //     $msi->model=$sins->model;
                            // }
                            $msi->out_id=$_mo->id;//6-30 新添加用于回溯 数据用的
                            $msi->return_order_id=$_ro->id;
                            $msi->implement_time=$time;
                            $msi->save();
                            //添加库存的修改记录
                            $mwf=new MaintenanceWarehouseFlow;
                            $mwf->mw_id=$mw->id;
                            $mwf->type=1;//入库
                            $mwf->item_id=$msi->id;
                            $mwf->number=$msi->number;
                            $mwf->created_by=$user->id;
                            $mwf->save();
                        }
                        //修改 该出库申请的退货个数
                        if($moo->return_number+$_ro->number==$moo->number){
                            $moo->status=3;//如果已经退完货  该条出库申请 改为 已经退货
                        }
                        $moo->return_number=$moo->return_number+$_ro->number;
                        $moo->save();
                    
                        // 修改库存的数量
                        $mw->number=$mw->number+$_ro->number;
                        $mw->save();
                    
                        //修改订单的 产品信息
                        $order=Orders::find($_ro->order_id);
                        //更改 退库申请 为成功
                        $_ro->status=1;
                        $_ro->save();
                    }
                }
            }
            foreach($return_type as $rt){
                $opr=OrderPayRecord::find($rt["id"]);
                if(is_null($opr) || $opr->status==0){
                    $response = Lang::get("scs_error.order_return_error_40050");
                    break;
                }
                if($rt["amount"]*100 > $opr->amount){
                    $response = Lang::get("scs_error.order_return_error_40050");
                    break;
                }
                $ror=new ReturnOrderRecord;
                $ror->order_pay_id=$rt["id"];
                $ror->return_order_id=$return_order_id;
                $ror->pay_type=$opr->pay_type;
                $ror->amount=$rt["amount"]*100;
                $ror->save();
            }
            foreach ($cancel_arr as $_pid) {//推套餐卡的逻辑   
                $scc=ServiceCardConsumption::where("product_id",$_pid)->where("type",0)->where("status",1)->first();
                $scc->status=3;
                $scc->save();
                DB::table("service_card_detail_pack")->where("id",$scc->service_card_detail_pack_id)->increment("curr_number");//恢复套餐卡次数
                $sccr=new ServiceCardConsumptionReturn();
                $sccr->order_id=$scc->order_id;
                $sccr->return_order_id=$return_order_id;
                $sccr->service_card_detail_pack_id=$scc->service_card_detail_pack_id;
                $sccr->type=$scc->type;
                $sccr->product_id=$scc->product_id;
                $sccr->save();

            }
            $response=Orders::refund($return_order_id,$user->id,'sc');
            ReturnOrderItem::where('status',0)->where('return_order_id',$return_order_id)->update(array('status'=>1));
            $ro->status=1;
            $ro->implement_time=date("Y-m-d H:i:s",time()+Config::get("config.report_time_diff"));
            $ro->approver=$approver;
            $ro->approver_name=$approver_name;
            $ro->save();

            return $response;
        });
        
    }
    
    /**
     * @Author:      zwh
     * @DateTime:    2016-8-12 19:18:24
     */
    public static function returnItem($user,$type,$item_id,$product_type,$order_product_item_id,$order_id,$number,$moo_ids,$return_order_id,$return_orders){
        if($number<=0){
            return $return_orders;
        }
        $moo=MaintenanceOutOrder::find($moo_ids[0]);
        if($number<= $moo->number-$moo->return_number){
            //记录 库存退货记录
            $mro=new MaintenanceReturnOrder();
            $mro->shop_id=$user->shop_id;
            $mro->status=0;
            $mro->type=$type;
            $mro->item_id=$item_id;
            $mro->product_type=$product_type;
            $mro->product_item_id=$order_product_item_id;
            $mro->order_id=$order_id;
            $mro->number=$number;
            $mro->out_order_id=$moo->id;
            $mro->source='return_order';
            $mro->return_order_id=$return_order_id;
            $mro->save();
            $return_orders[]=$mro;
            return $return_orders;
        }else{
            $mro=new MaintenanceReturnOrder();
            $mro->shop_id=$user->shop_id;
            $mro->status=0;
            $mro->type=$type;
            $mro->item_id=$item_id;
            $mro->product_type=$product_type;
            $mro->product_item_id=$order_product_item_id;
            $mro->order_id=$order_id;
            $mro->number=$moo->number-$moo->return_number;
            $mro->out_order_id=$moo->id;
            $mro->source='return_order';
            $mro->return_order_id=$return_order_id;
            $mro->save();
            $return_orders[]=$mro;
            array_shift($moo_ids);
            $number=$number-($moo->number-$moo->return_number);
            return ReturnOrderItem::returnItem($user,$type,$item_id,$product_type,$order_product_item_id,$order_id,$number,$moo_ids,$return_order_id,$return_orders);
        }
    }

    /**
     * @Author:      lyt
     * @DateTime:  2017-08-04 11:14:36
     * @Description: 退货产品
     */
    public static function getByOrderId($return_order_id){
        $roi=ReturnOrderItem::where('return_order_id',$return_order_id)->whereIn('status',array(0,1))->get();
        foreach($roi as $_roi){
            switch ($_roi->product_type) {
                case 'enterprise':
                    if($_roi->type!=3){
                        if($_roi->type!=4){//如果是
                            $item=OrderProductEsItem::find($_roi->order_product_item_id);
                            $opep=OrderProductEsPackage::find($item->order_product_package_id);
                            if($item->type==1){
                                // if($item->item_type==0){
                                    $si=SupplyItem::getCacheItemInfo($item->item_id);
                                // }else{
                                //     $si=SupplyItemNonStandard::getCacheItemInfo($item->item_id);
                                // }
                                $_roi->brand_name=$si->brand_name;
                                $_roi->item_name=$item->item_name;
                                $_roi->scf_name=$si->scf_name;
                                $_roi->specification=$si->specification;
                            }else{
                                $_roi->item_name=$item->item_name;
                            }      
                            $_roi->package_name=$opep->package_name;                         
                        }else{//如果是退的产品 泽是一个包结构
                            $opep_arr=OrderProductEsPackage::with("item")->where("order_product_id",$_roi->order_product_id)->get();
                            $op=OrderProduct::find($_roi->order_product_id);
                            foreach ($opep_arr as $key => $value){                                    
                                foreach ($value->item as $_item) {
                                    if($_item->type==1){
                                        // if($_item->item_type==0){
                                            $item_info=SupplyItem::getCacheItemInfo($_item->item_id);
                                            $_item->scf_name=$item_info->scf_name;
                                            $_item->subject=$item_info->subject;
                                            $_item->subject_name=$item_info->subject_name;
                                            $_item->brand_name=$item_info->brand_name;
                                            $_item->specification=$item_info->specification;
                                            $_item->series_name=$item_info->series_name;                                  
                                        // }else{
                                        //     $item_info=SupplyItemNonStandard::getCacheItemInfo($_item->item_id);
                                        //     $_item->scf_name=$item_info->scf_name;
                                        //     $_item->subject=$item_info->subject;
                                        //     $_item->subject_name=$item_info->subject_name;
                                        //     $_item->brand_name=$item_info->brand_name;
                                        //     $_item->specification=$item_info->specification;
                                        //     $_item->series_name=$item_info->series_name;
                                        // }
                                        $_item->temp_subject=($_item->temp_subject==0)?$_item->subject:$_item->temp_subject;
                                    }else{
                                        $_item->num=0;
                                        $_item->unit='个';
                                    }
                                }
                            }
                            $_roi->package_name=$op->product_name;
                            $_roi->item_arr=$opep_arr;
                        }  
                    }else{
                        $_roi->brand_name="";
                        $_roi->item_name="折扣均摊";
                        $_roi->scf_name="";
                        $_roi->specification="";
                    }
                    break;
                case 'activity':
                    if($_roi->type!=3){
                        if($_roi->type!=4){
                            $item=OrderProductAcItem::find($_roi->order_product_item_id);
                            $opacp=OrderProductAcPackage::find($item->order_product_package_id);
                            if($item->type==1){
                                // if($item->item_type==0){
                                    $si=SupplyItem::getCacheItemInfo($item->item_id);
                                // }else{
                                //     $si=SupplyItemNonStandard::getCacheItemInfo($item->item_id);
                                // }
                                $_roi->brand_name=$si->brand_name;
                                $_roi->item_name=$item->item_name;
                                $_roi->scf_name=$si->scf_name;
                                $_roi->specification=$si->specification;
                            }else{
                                $_roi->item_name=$item->item_name;
                            }
                            $_roi->package_name=$opacp->package_name;
                        }else{
                            $opacp=OrderProductAcPackage::with("item")->where("order_product_id",$_roi->order_product_id)->get();
                            $op=OrderProduct::find($_roi->order_product_id);
                            foreach ($opacp as $key => $value){                                
                                foreach ($value->item as $_item) {
                                    if($_item->type==1){
                                        // if($_item->item_type==0){
                                            $item_info=SupplyItem::getCacheItemInfo($_item->item_id);
                                            $_item->scf_name=$item_info->scf_name;
                                            $_item->subject=$item_info->subject;
                                            $_item->subject_name=$item_info->subject_name;
                                            $_item->brand_name=$item_info->brand_name;
                                            $_item->specification=$item_info->specification;
                                            $_item->series_name=$item_info->series_name;                                            
                                        // }else{
                                        //     $item_info=SupplyItemNonStandard::getCacheItemInfo($_item->item_id);
                                        //     $_item->scf_name=$item_info->scf_name;
                                        //     $_item->subject=$item_info->subject;
                                        //     $_item->subject_name=$item_info->subject_name;
                                        //     $_item->brand_name=$item_info->brand_name;
                                        //     $_item->specification=$item_info->specification;
                                        //     $_item->series_name=$item_info->series_name;
                                        // }

                                        $_item->temp_subject=($_item->temp_subject==0)?$_item->subject:$_item->temp_subject;
                                    }else{
                                        $_item->num=0;
                                        $_item->unit='个';
                                    }                                  
                                }                                
                            }
                            $_roi->package_name=$op->product_name;
                            $_roi->item_arr=$opacp;
                        }                        
                    }else{
                        $_roi->brand_name="";
                        $_roi->item_name="折扣均摊";
                        $_roi->scf_name="";
                        $_roi->specification="";
                    }
                    break;
                case 'promotion':
                    $item=OrderProductItem::find($_roi->order_product_item_id);
                    $opp=OrderProductPackage::find($item->order_product_package_id);
                    if($item->type==1){
                        // if($item->item_type==0){
                            $si=SupplyItem::getCacheItemInfo($item->item_id);
                        // }else{
                        //     $si=SupplyItemNonStandard::getCacheItemInfo($item->item_id);
                        // }
                        $_roi->brand_name=$si->brand_name;
                        $_roi->item_name=$item->item_name;
                        $_roi->scf_name=$si->scf_name;
                        $_roi->specification=$si->specification;
                    }else{
                        $_roi->item_name=$item->item_name;
                    }
                    $_roi->package_name=$opp->package_name;
                    break;
                case 'base':
                    if($_roi->type!=4){
                        $item=OrderProductBaseItem::find($_roi->order_product_item_id);
                        $op=OrderProduct::find($item->order_product_package_id);
                        if($item->type==1){
                            // if($item->item_type==0){
                                $si=SupplyItem::getCacheItemInfo($item->item_id);
                            // }else{
                            //     $si=SupplyItemNonStandard::getCacheItemInfo($item->item_id);
                            // }
                            $_roi->brand_name=$si->brand_name;
                            $_roi->item_name=$item->item_name;
                            $_roi->scf_name=$si->scf_name;
                            $_roi->specification=$si->specification;
                        }else{
                            $_roi->item_name=$item->item_name;
                        }
                        $_roi->package_name=$op->product_name;
                    }else{
                        $opp=OrderProductBaseItem::where("order_product_package_id",$_roi->order_product_id)->get();
                        $op=OrderProduct::find($_roi->order_product_id);
                        foreach ($opp as $key=>$_item) {
                            if($_item->type==1){
                                // if($_item->item_type==0){
                                    $item_info=SupplyItem::getCacheItemInfo($_item->item_id);
                                    $_item->scf_name=$item_info->scf_name;
                                    $_item->subject=$item_info->subject;
                                    $_item->subject_name=$item_info->subject_name;
                                    $_item->brand_name=$item_info->brand_name;
                                    $_item->specification=$item_info->specification;
                                    $_item->series_name=$item_info->series_name;                                  
                                // }else{
                                //     $item_info=SupplyItemNonStandard::getCacheItemInfo($_item->item_id);
                                //     $_item->scf_name=$item_info->scf_name;
                                //     $_item->subject=$item_info->subject;
                                //     $_item->subject_name=$item_info->subject_name;
                                //     $_item->brand_name=$item_info->brand_name;
                                //     $_item->specification=$item_info->specification;
                                //     $_item->series_name=$item_info->series_name;
                                // }
                                $_item->temp_subject=($_item->temp_subject==0)?$_item->subject:$_item->temp_subject;
                            }else{
                                $_item->num=0;
                                $_item->unit='个';
                            }                            
                        }
                        $_roi->package_name=$op->product_name;
                        $_roi->item_arr=$opp;
                    }                    
                    break;
                case 'non_standard':
                    if($_roi->type!=4){
                        $item=OrderProductNonStandard::find($_roi->order_product_item_id);
                        $op=OrderProduct::find($item->order_product_id);
                        if($item->service_type==1){
                            // if($item->type==0){
                                $si=SupplyItem::getCacheItemInfo($item->item_id);
                            // }else{
                            //     $si=SupplyItemNonStandard::getCacheItemInfo($item->item_id);
                            // }
                            $_roi->brand_name=$si->brand_name;
                            $_roi->item_name=$item->name;
                            $_roi->scf_name=$si->scf_name;
                            $_roi->specification=$si->specification;
                        }else{
                            $_roi->item_name=$item->name;
                        }
                        $_roi->package_name=$op->product_name;
                    }else{
                        $opn=OrderProductNonStandard::where("order_product_id",$_roi->order_product_id)->where('status',1)
                            ->get();
                        $op=OrderProduct::find($_roi->order_product_id);
                        foreach ($opn as $key=>$value) {
                            //判断产品项是非标还是标准配件
                            if($value->service_type==1){
                                // if($value->type==0){
                                    $item_info=SupplyItem::getCacheItemInfo($value->item_id);
                                    $value->scf_name=$item_info->scf_name;
                                    $value->subject=$item_info->subject;
                                    $value->subject_name=$item_info->subject_name;
                                    $value->brand_name=$item_info->brand_name;
                                    $value->specification=$item_info->specification;
                                    $value->series_name=$item_info->series_name;
                                // }else{
                                //     $item_info=SupplyItemNonStandard::getCacheItemInfo($value->item_id);
                                //     $value->scf_name=$item_info->scf_name;
                                //     $value->subject=$item_info->subject;
                                //     $value->subject_name=$item_info->subject_name;
                                //     $value->brand_name=$item_info->brand_name;
                                //     $value->specification=$item_info->specification;
                                //     $value->series_name=$item_info->series_name;
                                // }
                                $value->temp_subject=$value->subject;
                            }else{
                                $value->num=0;
                                $value->unit='个';
                            }                            
                        }
                        $_roi->package_name=$op->product_name;
                        $_roi->item_arr=$opn;
                    }                    
                    break;
                case 'service_card':
                    if($_roi->type!=4){
                        $item=OrderProductScItem::find($_roi->order_product_item_id);
                        $op=OrderProduct::find($item->order_product_id);
                        if($item->type==1){
                            // if($item->item_type==0){
                                $si=SupplyItem::getCacheItemInfo($item->item_id);
                            // }else{
                            //     $si=SupplyItemNonStandard::getCacheItemInfo($item->item_id);
                            // }
                            $_roi->brand_name=$si->brand_name;
                            $_roi->item_name=$item->item_name;
                            $_roi->scf_name=$si->scf_name;
                            $_roi->specification=$si->specification;
                        }else{
                            $_roi->item_name=$item->item_name;
                        }
                        $_roi->package_name=$op->product_name;
                    }else{
                        $opp=OrderProductScItem::where("order_product_id",$_roi->order_product_id)->get();
                        $op=OrderProduct::find($_roi->order_product_id);
                        foreach ($opp as $key=>$_item) {
                            if($_item->type==1){
                                // if($_item->item_type==0){
                                    $item_info=SupplyItem::getCacheItemInfo($_item->item_id);
                                    $_item->scf_name=$item_info->scf_name;
                                    $_item->subject=$item_info->subject;
                                    $_item->subject_name=$item_info->subject_name;
                                    $_item->brand_name=$item_info->brand_name;
                                    $_item->specification=$item_info->specification;
                                    $_item->series_name=$item_info->series_name;                                  
                                // }else{
                                //     $item_info=SupplyItemNonStandard::getCacheItemInfo($_item->item_id);
                                //     $_item->scf_name=$item_info->scf_name;
                                //     $_item->subject=$item_info->subject;
                                //     $_item->subject_name=$item_info->subject_name;
                                //     $_item->brand_name=$item_info->brand_name;
                                //     $_item->specification=$item_info->specification;
                                //     $_item->series_name=$item_info->series_name;
                                // }
                                $_item->temp_subject=($_item->temp_subject==0)?$_item->subject:$_item->temp_subject;
                            }else{
                                $_item->num=0;
                                $_item->unit='个';
                            }                            
                        }
                        $_roi->package_name=$op->product_name;
                        $_roi->item_arr=$opp;
                    }                    
                    break;
            }        
        }
        return $roi;
    }

}